package guda.house.dal.dao.impl;

import guda.grape.autogen.common.BaseDAO;
import guda.house.dal.dao.BillExtDAO;
import guda.house.dal.dataobject.BillExtDO;
import guda.grape.autogen.common.page.BaseQuery;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BillExtDAOImpl extends BaseDAO implements BillExtDAO {

    @Override
	public Long insert(BillExtDO billExt) {
	      try {
                return (Long) getSqlMapperW().insert("bill_ext.insert",billExt);
          } catch (Exception e) {
                throw new RuntimeException(e);
          }

	}

    @Override
	public BillExtDO getBillExtById(Long billId) {
	    return (BillExtDO)getSqlMapClientTemplate().queryForObject("bill_ext.getBillExtById", billId);
	}

    @Override
	public boolean delBillExtById(Long billId) {
	    int num = 0;
        try {
            num = getSqlMapperW().delete("bill_ext.delBillExtById",billId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(num>0){
            return true;
        }else{
            return false;
        }
	}

    @Override
	public List<BillExtDO> getBillExtByIds(List idsList) {
        Map m = new HashMap();
        m.put("idsList",idsList);
		return getSqlMapClientTemplate().queryForList("bill_ext.selectByIds", m);
	}

    @Override
	public void cleanAutoIncrement(Long billId) {
	    try {
            getSqlMapperW().update("bill_ext.cleanAutoIncrement",billId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
	}

    @Override
    public List<BillExtDO> selectForPage(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("bill_ext.selectForPage", baseQuery);
    }

    @Override
    public int countForPage(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("bill_ext.countForPage",baseQuery);
    }

    @Override
    public void updateByIdSelective(BillExtDO billExt) {
        try {
            getSqlMapperW().update("bill_ext.updateByIdSelective",billExt);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<BillExtDO> selectForDeposit(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("bill_ext.selectForDeposit", baseQuery);
    }

    @Override
    public int countForDeposit(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("bill_ext.countForDeposit",baseQuery);
    }

    @Override
    public List<BillExtDO> selectForUnpay(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("bill_ext.selectForUnpay", baseQuery);
    }

    @Override
    public int countForUnpay(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("bill_ext.countForUnpay",baseQuery);
    }

    @Override
    public Long statBill(List<Long> suitIdList, String gmtDate, Integer isPayed,List<Long> billTypeIdList) {
        Map m = new HashMap();
        m.put("suitIdList",suitIdList);
        m.put("gmtDate",gmtDate);
        m.put("isPayed",isPayed);
        m.put("billTypeIdList",billTypeIdList);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_ext.statBill", m);
    }

    @Override
    public Long statBill(List<Long> suitIdList, String gmtDate, Integer isPayed, Long billTypeId) {
        Map m = new HashMap();
        m.put("suitIdList",suitIdList);
        m.put("gmtDate",gmtDate);
        m.put("isPayed",isPayed);
        m.put("billTypeId",billTypeId);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_ext.statBill", m);
    }

    @Override
    public List<BillExtDO> getByPayId(long payId) {
        return getSqlMapClientTemplate().queryForList("bill_ext.getByPayId", payId);
    }

    @Override
    public Long statDichanDiscount(List<Long> suitIdList, String gmtDate) {
        Map m = new HashMap();
        m.put("suitIdList",suitIdList);
        m.put("gmtDate",gmtDate);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_ext.statDichanDiscount", m);
    }

    @Override
    public Long statSelfDiscount(List<Long> suitIdList, String gmtDate) {
        Map m = new HashMap();
        m.put("suitIdList",suitIdList);
        m.put("gmtDate",gmtDate);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_ext.statSelfDiscount", m);
    }

    @Override
    public Long statRefund(List<Long> suitIdList, String gmtDate, Long billTypeId) {
        Map m = new HashMap();
        m.put("suitIdList",suitIdList);
        m.put("gmtDate",gmtDate);
        m.put("billTypeId",billTypeId);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_ext.statRefund", m);
    }

    @Override
    public Long statRefund(List<Long> suitIdList, String gmtDate, List<Long> billTypeIdList) {
        Map m = new HashMap();
        m.put("suitIdList",suitIdList);
        m.put("gmtDate",gmtDate);
        m.put("billTypeIdList",billTypeIdList);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_ext.statRefund", m);
    }

    @Override
    public Long statBillByTime(List<Long> suitIdList, Date gmtStart, Date endStart) {
        Map m = new HashMap();
        m.put("suitIdList",suitIdList);
        m.put("startDate",gmtStart);
        m.put("endDate",endStart);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_ext.statBillByTime", m);
    }

    @Override
    public Long statPaidBill(List<Long> billIdList) {
        Map m = new HashMap();
        m.put("billIdList",billIdList);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_ext.statPaidBill", m);
    }

}

